﻿using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Web.Security;
using HRProject.Code.Common;

namespace HRProject.Code.DTO
{
    public class BLTask
    {
        private Guid id;

        public Guid Id
        {
            get { return id; }
            set { id = value; }
        }
        private string name;

        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        private string description;

        public string Description
        {
            get { return description; }
            set { description = value; }
        }
        private BLTaskType type;

        public BLTaskType Type
        {
            get { return type; }
            set { type = value; }
        }
        private DateTime estimateStartDate;

        public DateTime EstimateStartDate
        {
            get { return estimateStartDate; }
            set { estimateStartDate = value; }
        }

        public string HtmlEstimateStartDate
        {
            get 
            {
                if (Constant.DefaultMinDate.Equals(estimateStartDate))
                    return string.Empty;
                return estimateStartDate.ToString("dd/MM/yyyy HH:mm");
            }
        }

        private DateTime estimateFinishDate;

        public DateTime EstimateFinishDate
        {
            get { return estimateFinishDate; }
            set { estimateFinishDate = value; }
        }

        public string HtmlEstimateFinishDate
        {
            get
            {
                if (Constant.DefaultMinDate.Equals(estimateFinishDate))
                    return string.Empty;
                return estimateFinishDate.ToString("dd/MM/yyyy HH:mm");
            }
        }

        private DateTime realStartDate;

        public DateTime RealStartDate
        {
            get { return realStartDate; }
            set { realStartDate = value; }
        }

        public String HtmlRealStartDate
        {
            get
            {
                if (Constant.DefaultMinDate.Equals(realStartDate))
                    return string.Empty;
                return realStartDate.ToString("dd/MM/yyyy HH:mm");
            }
        }

        private DateTime realFinishDate;

        public DateTime RealFinishDate
        {
            get { return realFinishDate; }
            set { realFinishDate = value; }
        }

        public String HtmlRealFinishDate
        {
            get
            {
                if (Constant.DefaultMinDate.Equals(realFinishDate))
                    return string.Empty;
                return realFinishDate.ToString("dd/MM/yyyy HH:mm");
            }
        }

        private DateTime createDate;

        public DateTime CreateDate
        {
            get { return createDate; }
            set { createDate = value; }
        }
        private DateTime updateDate;

        public DateTime UpdateDate
        {
            get { return updateDate; }
            set { updateDate = value; }
        }
        private Guid createUserId;

        public Guid CreateUserId
        {
            get { return createUserId; }
            set { createUserId = value; }
        }
        private Guid updateUserId;

        public Guid UpdateUserId
        {
            get { return updateUserId; }
            set { updateUserId = value; }
        }
        private long dataSignature;

        public long DataSignature
        {
            get { return dataSignature; }
            set { dataSignature = value; }
        }

        private Color displayColor;

        public Color DisplayColor
        {
            get { return displayColor; }
            set { 
                displayColor = value;
            }
        }

        private Guid inChargeUserId;

        public Guid InChargeUserId
        {
            get { return inChargeUserId; }
            set { inChargeUserId = value; }
        }

        public string InChargeUserName
        {
            get
            {
                MembershipUser user = Membership.GetUser(inChargeUserId);
                if (user != null)
                {
                    return user.UserName;
                }
                return string.Empty;
            }
        }

        public string ActionBar
        {
            get
            {
                StringBuilder result = new StringBuilder("<div style=\"float:left;width:100%;height:100%\" onmouseover=\"treeNodeMove(this);\" onmouseout=\"treeNodeOut(this);\">");
                result.Append("<div class=\"actionbar\" style=\"top:0px\">");
                if (BLAuthentication.IsEditAllowed)
                {
                    result.Append("<div class=\"item edit\" onclick=\"editTask(this);\"></div>");
                }
                if (BLAuthentication.IsRemoveAllowed)
                {
                    result.Append("<div class=\"item remove\" onclick=\"removeTask(this);\"></div>");
                }
                result.Append("<input type=\"hidden\" name=\"id\" value=\"" + Id + "\"/>");
                result.Append("</div>");
                result.Append("</div>");
                return result.ToString();
            }
        }
    }
}
